local skel = fk.CreateSkill {
  name = "rmt__zilve",
}

skel:addEffect("viewas", {
  pattern = "nullification",
  prompt = "#rmt__zilve",
  card_filter = Util.FalseFunc,
  times = function (self, player)
    return 1 - player:usedSkillTimes(skel.name, Player.HistoryTurn)
  end,
  view_as = function (self, player, cards)
    if player.hp == player:getHandcardNum() then return end
    local card = Fk:cloneCard("nullification")
    card.skillName = skel.name
    return card
  end,
  before_use = function (self, player, use)
    if player.hp > player:getHandcardNum() then
      player:drawCards(player.hp - player:getHandcardNum(), skel.name)
    elseif player.hp < player:getHandcardNum() then
      player.room:askToDiscard(player, {
        min_num = player:getHandcardNum() - player.hp,
        max_num = player:getHandcardNum() - player.hp,
        include_equip = false,
        skill_name = skel.name,
        cancelable = false,
      })
    end
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryTurn) == 0 and 
    (player.hp > player:getHandcardNum() or (player.hp < player:getHandcardNum() and 
    #table.filter(player:getCardIds("h"), function (id) return not player:prohibitDiscard(id)end) >= player:getHandcardNum() - player.hp))
  end,
  enabled_at_response = function(self, player, response)
    return not response and player:usedSkillTimes(skel.name, Player.HistoryTurn) == 0 and 
    (player.hp > player:getHandcardNum() or (player.hp < player:getHandcardNum() and 
    #table.filter(player:getCardIds("h"), function (id) return not player:prohibitDiscard(id)end) >= player:getHandcardNum() - player.hp))
  end,
})

skel:addEffect(fk.CardUseFinished, {
  can_refresh = function(self, event, target, player, data)
    return target == player and data.responseToEvent and data.responseToEvent.card.trueName == "nullification"
    and data.card.trueName == "nullification" and table.contains(data.card.skillNames, skel.name)
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:damage{
      from = player,
      to = player,
      damage = 1,
      skillName = skel.name,
    }
  end,
})


Fk:loadTranslationTable{
  ["rmt__zilve"] = "梓略",
  [":rmt__zilve"] = "每回合限一次，你可以将手牌调整至体力值，视为使用【无懈可击】；若以此法抵消了【无懈可击】，你受到1点伤害。",
  ["#rmt__zilve"] = "梓略：你可以将手牌调整至体力值，视为使用【无懈可击】。",

  ["$rmt__zilve1"] = " ",
  ["$rmt__zilve2"] = " ",
}

return skel
